package cn.xiqi.cms.oper;

import cn.xiqi.cms.hibernate.DAO.AccountDAO;
import cn.xiqi.cms.hibernate.DAO.AccountDAOImpl;
import cn.xiqi.cms.hibernate.beans.Accountinfo;
import cn.xiqi.cms.hibernate.service.AccountService;
import cn.xiqi.cms.hibernate.service.AccountServiceImpl;

public class AccountOper {
	private AccountService service;
	
	public AccountOper(){
		AccountDAO dao = new AccountDAOImpl();
		
		service = new AccountServiceImpl();
		service.setDao(dao);
	}
	
	public int register(String account, String password, int userid){
		int id;
		Accountinfo record;
		
		record = new Accountinfo(account, password, userid);
		id = service.register(record);
		return id;
	}
	
	public boolean login(String username, String password){
		boolean isLogin = false;
		
		isLogin = service.login(username, password);
		return isLogin;
	}
	
	public boolean isExist(String username){
		boolean exist;
		
		exist = service.isExist(username);
		return exist;
	}
	
	public Accountinfo getByUser(int userid){
		Accountinfo record;
		
		record = service.getByUsr(userid);
		return record;
	}
	
	public boolean delete(int userid){
		boolean delete = false;
		Accountinfo record;
		
		record = getByUser(userid);
		delete = service.delete(record);
		return delete;
	}
	
	public boolean changepsw(int userid, String password){
		boolean b = false;
		
		b = service.changePsw(userid, password);
		return b;
	}
	
}
